#include "abstractmaskwidget.h"

#include <QKeyEvent>

AbstractMaskWidget::AbstractMaskWidget(QDialog *parent) :
    QDialog(parent)
{
    updateUI();

    setWindowOpacity(0.7);//不透明度
    setBgColor(QColor(0, 0, 0));

    //不设置主窗体则遮罩层大小为默认桌面大小   遮罩层就是一个无边框的窗体
    //this->setGeometry(qApp->desktop()->geometry());
    this->setWindowFlags(Qt::FramelessWindowHint );

    setStyleSheet("QLabel {color: red; font-size: 30px }");
}

void AbstractMaskWidget::updateUI()
{
    resize(500, 500);
}

AbstractMaskWidget::~AbstractMaskWidget()
{

}

void AbstractMaskWidget::setBgColor(const QColor &bgColor)
{
    QPalette palette = this->palette();
    palette.setBrush(QPalette::Background, bgColor);
    this->setPalette(palette);
}

bool AbstractMaskWidget::event(QEvent *event)
{
    if(event->type() == QEvent::KeyPress)
    {
        this->hide();
        return true;
    }else if(event->type() == QEvent::Show) {
        this->activateWindow();//使能当前窗口活跃，以接受键盘处理
    }

    return QWidget::event(event);
}


